package com.quick.develop.business.controller;

import com.quick.develop.framework.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.quick.develop.framework.common.utils.PageResult;
import com.quick.develop.framework.common.utils.Result;
import com.quick.develop.business.convert.EnvironmentalTargetConvert;
import com.quick.develop.business.entity.EnvironmentalTargetEntity;
import com.quick.develop.business.service.EnvironmentalTargetService;
import com.quick.develop.business.query.EnvironmentalTargetQuery;
import com.quick.develop.business.vo.EnvironmentalTargetVO;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 环境指标目标任务
 *
 * @author GJH 1906559468@qq.com
 * @since 1.0.0 2024-01-27
 */
@RestController
@RequestMapping("business/environmental_target")
@Tag(name = "环境指标目标任务")
@AllArgsConstructor
public class EnvironmentalTargetController {

    private final EnvironmentalTargetService environmentalTargetService;

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<EnvironmentalTargetVO>> page(EnvironmentalTargetQuery query) {
        PageResult<EnvironmentalTargetVO> page = environmentalTargetService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<EnvironmentalTargetVO> get(@PathVariable("id") String id) {
        EnvironmentalTargetEntity entity = environmentalTargetService.getById(id);

        return Result.ok(EnvironmentalTargetConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody EnvironmentalTargetVO vo) {
        environmentalTargetService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    public Result<String> update(@RequestBody EnvironmentalTargetVO vo) {
        environmentalTargetService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<String> idList) {
        environmentalTargetService.delete(idList);

        return Result.ok();
    }

    @PostMapping(value = "export")
    @Operation(summary = "导出数据")
    public Result<?> dynamicExportExcel(@RequestBody EnvironmentalTargetQuery query) {
        environmentalTargetService.dynamicExportExcel(query);

        return Result.ok();
    }

    @PostMapping(value = "import")
    @Operation(summary = "导出数据")
    public Result<?> dynamicImportExcel(@RequestParam(value = "file") MultipartFile file) {
        environmentalTargetService.dynamicImportExcel(file);

        return Result.ok();
    }

    @GetMapping(value = "business/{businessKey}")
    @Operation(summary = "获取数据详情，根据业务Key")
    public Result<EnvironmentalTargetVO> getEnvironmentalTargetByBusinessKey(@PathVariable(value = "businessKey") String businessKey) {
        return Result.ok(environmentalTargetService.getEnvironmentalTargetByBusinessKey(businessKey));
    }

    @PostMapping(value = "batch/update")
    @Operation(summary = "批量更新数据")
    public Result<?> batchUpdate(@RequestBody List<EnvironmentalTargetVO> list) {
        environmentalTargetService.batchUpdateById(list);
        return Result.ok();
    }

    @Operation(summary = "批量创建数据")
    @PostMapping(value = "batch/create")
    public Result<?> batchCreate(@RequestBody List<EnvironmentalTargetVO> list) {
        environmentalTargetService.batchSave(list);
        return Result.ok();
    }

    @Operation(summary = "根据Key（自定义）查询数据列表)")
    @GetMapping(value = "keys")
    public Result<List<EnvironmentalTargetVO>> getListByKeys(EnvironmentalTargetQuery query) {
        environmentalTargetService.getListByKeys(query);
        return Result.ok();
    }
}